package com.seed.core.query.pojo;

import com.seed.core.column.Column;
import com.seed.core.enumeration.PropertyType;
import com.seed.core.pojo.seed.*;

import java.util.LinkedHashMap;

public class Declared extends LinkedHashMap<String, Declared> {
    private PropertyType type;
    private Property property;

    public Declared(PropertyType type) {
        this.type = type;
    }

    public Declared(Column column) {
        this.property = column;
        this.type = PropertyType.column;
    }

    public Declared(Relation relation) {
        this.property = relation;
        if(property instanceof Habtms) this.type = PropertyType.habtm;
        else if(property instanceof HasManys) this.type = PropertyType.hasMany;
        else if(property instanceof HasOnes) this.type = PropertyType.hasOne;
        else if(property instanceof BelongsTos) this.type = PropertyType.belongsTo;
    }

    public static Declared of(Column column) {
        return new Declared(column);
    }

    public static Declared of(Relation relation) {
        return new Declared(relation);
    }

    public PropertyType getType() {
        return type;
    }

    public void setType(PropertyType type) {
        this.type = type;
    }

    public Property getProperty() {
        return property;
    }

    public void setProperty(Property property) {
        this.property = property;
    }
}
